<?php
	$validation_rules = array(
		"onair_episode_no" => array(
			"required" => true,
            'positiveInt' => true,
            'epsExist' => true,
            'maxlength' => 9
		),
        'programme_title_cn' => array(
            'maxlength' => 255
        ),
        'programme_title_en' => array(
            'maxlength' => 255
        ),
        'programme_path' => array(
            'required' => true,
            #'path' => true,
            'maxlength' => 255
        ),
		"award_title_chinese" => array(
			"maxlength" => "255",
		), 
		"award_title_english" => array(
			"maxlength" => "255"
		),
		"award_type" => array(
			"maxlength" => "255"
		),
		"year" => array(		      
			"maxlength" => '9',
			"number" => true,
			'positiveInt' => true
        ),
        "publish_datetime[]" => array(		      
            'required' => true	
        ),
       "expire_datetime[]" => array(		      
			'required' => true			
        )
    );
?>

<?php
    if ($act==='view') {
        FormHelper::setReadonly(true);
        $validation_rules = array();
    }

	$award = isset($data['award']) ? $data['award'] : array();
	$award->year = ($award->year == 0) ? '' : $award->year;
	$episode = isset($data['episode']) ? $data['episode'] : "";
	$programme = isset($data['programme']) ? $data['programme'] : "";
	$award_json_list = isset($data['award_json_list']) ? $data['award_json_list'] : array();
	$form_action = ($act === 'view') ? "info_switch.html?type=award" : ( ($act === 'add') ? "add_award.html?type=award&act=edit" : "update_award.html?type=award&act=edit");
	$publish = isset($data['unpublish']) ? $data['unpublish'] : 0;
	$from    = isset($data['from']) ? $data['from'] : '';
?>

<div id="award" class="mod ui-widget-content ui-helper-clearfix ui-corner-all <?php echo $act; ?>">

    <div class="hd ui-widget-header ui-helper-clearfix ui-corner-all"><h2><?php echo $act_text; ?> Award</h2></div>

    <div class="bd">
    <?php FormHelper::StartForm('ane', AC::PDES_BASE_URL.$form_action) ?>
		    <?php FormHelper::ErrorMessages($errors) ?>
			<?php if($act != 'add') FormHelper::HiddenField('id', $award->id) ?>
	        <?php if($act != 'add') FormHelper::HiddenField('episode_id', $award->episode_id) ?>
			<?php FormHelper::HiddenField('check_used', $data['check_used']) ?>
			<?php FormHelper::HiddenField('status', $award->status) ?>
			<?php FormHelper::HiddenField('created_at', $award->created_at) ?>
			<?php FormHelper::HiddenField('created_by', $award->created_by) ?>
			<?php FormHelper::HiddenField('modified_at', $award->modified_at) ?>
			<?php FormHelper::HiddenField('modified_by', $award->modified_by) ?>
			<?php FormHelper::HiddenField('from', $from) ?>
    	<fieldset class="ui-widget-content">
            <legend class="ui-widget-header">Find Programme Record</legend>
<?php
	if ($act != 'add')
	{
?>
			<?php FormHelper::ProtectedField($programme->id, 'Programme ID');?>
            <?php FormHelper::ProtectedField($award->id, 'Award ID');?>
            <?php 
				FormHelper::ProtectedField($programme->zh_programme_name, 'Programme Title (Chinese)');
				FormHelper::ProtectedField($programme->en_programme_name, 'Programme Title (English)');
				FormHelper::ProtectedField($programme->path, 'Programme Path') ?>
			<?php FormHelper::ProtectedField($episode->onair_episode_no, 'On Air Episode No.') ?>
			<?php FormHelper::HiddenField('programme_id', $programme->id) ?>
			<?php FormHelper::HiddenField('onair_episode_no', $episode->onair_episode_no) ?>
<?php
	}
	else
	{
?>
            <input id="programme_id" name="programme_id" type="hidden" value="<?php echo $award->programme_id;?>" />
			<input id="programme_eps" type="hidden" value="<?php echo $award->onair_episode_no;?>" />

            <div class="form-item">
                <span class="grid-l"><label><ins>**</ins>Programme Title (Chinese)</label> :</span>
                <span class="grid-r">
                <input id="programme_title_cn" name="programme_title_cn" type="text" class="text" autocomplete="off" 
                    value="<?php echo htmlentities($award->programme_title_cn, ENT_QUOTES, 'UTF-8');?>" />
                </span>
            </div>
            <div class="form-item">
                <span class="grid-l"><label><ins>**</ins>Programme Title (English)</label> :</span>
                <span class="grid-r">
                <input id="programme_title_en" name="programme_title_en" type="text" class="text" autocomplete="off" 
                    value="<?php echo htmlentities($award->programme_title_en, ENT_QUOTES, 'UTF-8');?>" /> 
                </span>
            </div>

            <div class="form-item">
                <span class="grid-l"><label><ins>*</ins>Programme Path</label> :</span>
                <span class="grid-r">
                <input id="programme_path" name="programme_path" type="text" class="text" autocomplete="off" 
                    value="<?php echo htmlentities($award->programme_path, ENT_QUOTES, 'UTF-8');?>" /> 
                </span>
            </div>

            <?php FormHelper::TextField('onair_episode_no', $award->onair_episode_no, "On Air Episode No.", '', 'number', 1) ?>
<?php
	}
?>
	</fieldset>
    	<fieldset class="ui-widget-content">
    		<legend class="ui-widget-header">Award Information</legend>
			<?php 
				FormHelper::TextField('award_title_chinese', $award->award_title_chinese, 'Award Title (Chinese)', false, 'ruler input_status', 2);
				FormHelper::TextField('award_title_english', $award->award_title_english, 'Award Title (English)', false, 'ruler input_status', 2);
				FormHelper::TextField('award_type', $award->award_type, 'Award Type');
				
                $arr_cast_type = array(
                    'winners' => 'Winner(s)'
                );
				FormHelper::GlobalNameInput($arr_cast_type, $award_json_list, 1);
				
				FormHelper::TextField('year', $award->year, 'Year', '', 'number');
				FormHelper::TextArea('description', $award->description, 'Description'); ?>
<?php 
if(in_array($data['_gn'],array('admin','proofreader','editor'))){
    if( !is_array($award->publish_datetime) )
    {   
        $publish_datetime = empty($award->publish_datetime) ? array('','') :CommonUtils::formatDate($award->publish_datetime) ;
    }
    else
    {
        $publish_datetime = empty($award->publish_datetime) ? array('','') : $award->publish_datetime ;
    }
    if( !is_array($award->expire_datetime) )
    {   
        $expire_datetime  = empty($award->expire_datetime ) ? array('','') :CommonUtils::formatDate($award->expire_datetime)  ;
    }
    else
    {
        $expire_datetime  = empty($award->expire_datetime ) ? array('','') : $award->expire_datetime  ;
    }
 
    FormHelper::DateTimePicker('publish_datetime', $publish_datetime, 'Publish Date/Time (YYYY-MM-DD / HH:MM)',null,1);
	FormHelper::DateTimePicker('expire_datetime', $expire_datetime, 'Expiry Date/Time (YYYY-MM-DD / HH:MM)',null,1);
}
?>
            <?php
                $arr_cast_type = array(
                    'award_presenters' => 'Award Presenter(s)',
                    'nominees' => 'Nominee(s)',
                    'organizations' => 'Organizer(s)'
                );
            ?>
    		<?php FormHelper::GlobalNameInput($arr_cast_type, $award_json_list, 1) ?>

		</fieldset>
<?php
	if ($act != "add")
	{
?>
    	<fieldset class="ui-widget-content">
    		<legend class="ui-widget-header">Record Status and Access Log</legend>
        	    <?php FormHelper::ProtectedField(AC::$op_status[$award->status], 'Record Status', true) ?>
			    <?php FormHelper::ProtectedField($award->created_by, 'Created By') ?>
        	    <?php FormHelper::ProtectedField($award->created_at, 'Created At') ?>
         	    <?php FormHelper::ProtectedField($award->modified_by, 'Modified By') ?>       
        	    <?php FormHelper::ProtectedField($award->modified_at, 'Modified At') ?>
		</fieldset>
<?php
	}
?>

        <?php FormHelper::DisplayPublishLog($data['publishLog']); ?>
        <span class="buttons">
            <?php
                switch ($act) {
                    case 'add':
                        FormHelper::SubmitButton('create', 'Create'); 
                        FormHelper::ResetButton('reset', 'Reset');
                    break;
                    case 'edit':
                        FormHelper::SubmitButton('update', 'Update');
                        FormHelper::ResetButton('reset', 'Reset');
                    	FormHelper::Button('back', 'Back to list');
                    break;
					case 'view':
						/** modified by vanni for bug no:260 **/
						if($publish ==1){
                            CommonUtils::showUnpublishButton($data, $data['_g']);
                        }else{
                            if($award->status == AC::STATUS_DELETED){
								FormHelper::SubmitButton('recover', 'Recover');
							}else{
								FormHelper::SubmitButton('edit', 'Edit');
                                CommonUtils::showDeleteButton($data['publishLog']);
							}
						}
                    	FormHelper::Button('back', 'Back to list');
						break;
                }
            ?>
        </span>
    <?php FormHelper::EndForm() ?>

    </div>

</div>



<script>
    TVB.Pdes.oValidation = {
        form: document.forms['ane'],
        rules: <?php echo json_encode($validation_rules); ?>
    };
</script>
